// OptionHandler.cs
//

namespace ServiceAdmin.Config
{
    using System;
    using System.Drawing;
    using System.Globalization;
    using System.Reflection;
    using System.Resources;
    using System.Windows.Forms;


    /// <summary>
    /// Summary description for OptionHandler.
    /// </summary>
    public class OptionHandler
    {
        public static readonly   OptionHandler	Instance			= new OptionHandler();

		public const 	 string					OPTION_PATH			= @"Options.resx";
		public const 	 string					DEFAULT_VALUE		= "en-GB";
        private          ResourceManager		_languageRes		= null;
        private          OptionReader			_optionRes			= null;
        private          Icon					_defaultIcon		= null;
        private			 CultureInfo			_culture			= null;


		public OptionReader ResourceReader
		{
			get { return _optionRes; }
		}


		public string ImagePath
        {
            get { return Application.StartupPath + @"\images\"; }
        }


        public Icon DefaultIcon
        {
            get { return _defaultIcon; }
        }


        public ResourceManager Language
        {
            get { return _languageRes; }
        }


        /// <summary>
        /// Creates a new instance of OptionHandler
        /// </summary>
        private OptionHandler()
        {
            _languageRes                = new ResourceManager("Text", Assembly.GetExecutingAssembly());
            _optionRes                  = new OptionReader(OPTION_PATH);

            _defaultIcon                = OpenIcon(ImagePath + "app.ico");

			try
			{
				_culture = new CultureInfo(_optionRes.Language);
			}
			catch (ArgumentException)
			{
				_culture = new CultureInfo(DEFAULT_VALUE);
			}
        }


        public string GetLanguageRes(string name)
        {
            return _languageRes.GetString(name, _culture);
        }


        public Icon OpenIcon(string pathToImage)
        {
            try
            {
                return new Icon(pathToImage);
            }
            catch
            {
                return null;
            }
        }
    }
}